type ExamPayload = ReqPayLoad<ExamHeadType[]>;
// eslint-disable-next-line ts/consistent-type-definitions
type ExamGetter = {
  noExam: (store: ExamPayload) => boolean
}
interface ExamAction {
  doFetch: () => Promise<void>
  setTested: (index: number) => void
}

export const useMyExamStore = defineStore<
  "myExamStore",
  ExamPayload,
  ExamGetter,
  ExamAction
      >({
        id: "myExamStore",
        state: () => ({
          data: [
            {
              eid: 0,
              title: "",
              content: "",
              expire: 0,
              question_count: 0,
              total_score: 0,
              pass_score: 0,
              has_test: false,
            },
          ],
        }),

        actions: {
          async doFetch() {
            // fetch data
            this.data = (await $fetch("/api/exam/head")).data;
          },
          setTested(i) {
            if (i < this.data.length) {
              console.log(`set${i}to tested`);
              this.data[i].has_test = !this.data[i].has_test;
            }
          },
        },
        getters: {
          noExam: store => store.data.length === 0 || store.data[0].question_count === 0,
        },
        persist: {
          storage: persistedState.sessionStorage,
        },
      });
